/**
 * This javascript file checks for the brower/browser tab action.
 * It is based on the file menstioned by Daniel Melo.
 * Reference: http://stackoverflow.com/questions/1921941/close-kill-the-session-when-the-browser-or-tab-is-closed
 */
var validNavigation = false;

function wireUpEvents() {
  /**
   * For a list of events that triggers onbeforeunload on IE
   * check http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx
   *
   * onbeforeunload for IE and chrome
   * check http://stackoverflow.com/questions/1802930/setting-onbeforeunload-on-body-element-in-chrome-and-ie-using-jquery
   */
  var dont_confirm_leave = 0; //set dont_confirm_leave to 1 when you want the user to be able to leave withou confirmation
  var leave_message = 'Kindly provide your valuable suggestions on contact page before you leave?'
  function goodbye(e) {
    if (!validNavigation) {
      if (dont_confirm_leave!==1) {
        if(!e) e = window.event;
        //e.cancelBubble is supported by IE - this will kill the bubbling process.
        e.cancelBubble = true;
        e.returnValue = leave_message;
        //e.stopPropagation works in Firefox.
        if (e.stopPropagation) {
          e.stopPropagation();
          e.preventDefault();
        }
        //return works for Chrome and Safari
        return leave_message;
      }
    }
  }
  window.onbeforeunload=goodbye;

  // Attach the event keypress to exclude the F5 refresh
  $(document).bind('keypress', function(e) {
    if (e.keyCode == 116){
      validNavigation = true;
    }
  });

  // Attach the event click for all links in the page
  $("a").bind("click", function() {
    validNavigation = true;
  });

  // Attach the event submit for all forms in the page
  $("form").bind("submit", function() {
    validNavigation = true;
  });

  // Attach the event click for all inputs in the page
  $("input[type=submit]").bind("click", function() {
    validNavigation = true;
  });

}

// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
  wireUpEvents();
});

//How To Disable Right Click Using JQuery
$(document).ready(function(){
	$(document).bind("contextmenu",function(e){
	    return false;
	});
	});

/*var unique_id;
var unique_id2;
var unique_id3;

function onPageLoad()
{
	unique_id3 = $.gritter.add({
		// (string | mandatory) the heading of the notification
		title: 'Health Right!',
		// (string | mandatory) the text inside the notification
		text: 'You will get health notifications here.',
		// (string | optional) the image to display on the left
		image: '../images/hnw.jpg',
		// (bool | optional) if you want it to fade out on its own or just sit there
		sticky: false,
		// (int | optional) the time you want it to be alive for before fading out
		time: ''
	});
	
	$.gritter.add({
		// (string | mandatory) the heading of the notification
		 title: 'Drink Right!',
			// (string | mandatory) the text inside the notification
			text: 'You should drink water now.',
		// (string | optional) the image to display on the left
		image: '../images/hnw.jpg',
		// (bool | optional) if you want it to fade out on its own or just sit there
		sticky: false,
		// (int | optional) the time you want it to be alive for before fading out
		time: ''
	});
}


//Call on page load
$(onPageLoad);


// notification
window.setInterval((function(){
	 $.gritter.add({
		// (string | mandatory) the heading of the notification
		 title: 'Drink Right!',
			// (string | mandatory) the text inside the notification
			text: 'You should drink water now.',
		// (string | optional) the image to display on the left
		image: '../images/hnw.jpg',
		// (bool | optional) if you want it to fade out on its own or just sit there
		sticky: false,
		// (int | optional) the time you want it to be alive for before fading out
		time: ''
	});

	return false;

})
, 15000);


//notification
window.setInterval((function(){
		$.gritter.add({
		// (string | mandatory) the heading of the notification
		title: 'Walk Right!',
		// (string | mandatory) the text inside the notification
		text: 'You should take a short walk now.',
		// (string | optional) the image to display on the left
		image: '../images/hnw.jpg',
		// (bool | optional) if you want it to fade out on its own or just sit there
		sticky: false,
		// (int | optional) the time you want it to be alive for before fading out
		time: ''
	});

	return false;

})
, 30000);
*/